package com.rightsidetech.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.mall.dto.log.request.MallLogPageReq;
import com.rightsidetech.mall.dto.log.response.MallLogPageResp;
import com.rightsidetech.mall.mapper.MallCommodityLogMapper;
import com.rightsidetech.mall.service.MallCommodityLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import java.util.List;

@Service("mallCommodityLogService")
public class MallCommodityLogServiceImpl implements MallCommodityLogService {

    @Resource
    private MallCommodityLogMapper mallCommodityLogMapper;

    @Override
    public ResponseData<PageInfo<MallLogPageResp>> page(MallLogPageReq req) {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData<>(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        PageHelper.startPage(req.getPageNo(),req.getPageSize());
        List<MallLogPageResp> result =  mallCommodityLogMapper.selectPageList(req);
        return ResponseData.success(new PageInfo<>(result));
    }

    @Override
    public List<MallLogPageResp> selectList(MallLogPageReq req) {
        return mallCommodityLogMapper.selectPageList(req);
    }
}
